using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Xml;
using OracleInternal.Common;

namespace Oracle.ManagedDataAccess.Client
{
	internal class RegAndConfigRdr : ConfigBaseClass
	{
		private class ODTConfigFileInfoForRefCursors
		{
			internal DateTime lastModifiedTime;

			internal Hashtable storedProcList = new Hashtable();
		}

		public static DataTable GetRefCursorInfoForSP(string configFileAlongWithFullPath, string schemaName, string storedProcName)
		{
			CustomConfigFileReader customConfigFileReader = ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader;
			if (storedProcName == null || configFileAlongWithFullPath == null)
			{
				customConfigFileReader.InitEdmMapping();
				return null;
			}
			string text = schemaName + "." + storedProcName;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.RegAndConfigRdr, OracleTraceFuncName.GetRefCursorInfoForSP, " (REFCURSOR) GetRefCursorInfoForSP(" + text + ")\n");
			}
			DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(configFileAlongWithFullPath);
			ODTConfigFileInfoForRefCursors oDTConfigFileInfoForRefCursors = null;
			bool flag = false;
			string key = configFileAlongWithFullPath.Trim();
			if (flag = ConfigBaseClass.s_odtConfigNamesToRefCursorInfo.Contains(key))
			{
				oDTConfigFileInfoForRefCursors = (ODTConfigFileInfoForRefCursors)ConfigBaseClass.s_odtConfigNamesToRefCursorInfo[key];
				if (oDTConfigFileInfoForRefCursors.lastModifiedTime != lastWriteTimeUtc)
				{
					oDTConfigFileInfoForRefCursors = null;
					flag = false;
				}
			}
			if (!flag)
			{
				customConfigFileReader.InitEdmMapping();
				XmlDocument xmlDocument = new XmlDocument();
				XmlTextReader xmlTextReader = new XmlTextReader(configFileAlongWithFullPath);
				xmlDocument.Load(xmlTextReader);
				XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("oracle.manageddataaccess.client");
				if (elementsByTagName.Count > 0)
				{
					oDTConfigFileInfoForRefCursors = new ODTConfigFileInfoForRefCursors
					{
						lastModifiedTime = lastWriteTimeUtc
					};
					new ProviderConfig().ParseConfigParamsForODT(elementsByTagName[0], ref oDTConfigFileInfoForRefCursors.storedProcList);
					ConfigBaseClass.s_odtConfigNamesToRefCursorInfo[key] = oDTConfigFileInfoForRefCursors;
				}
				xmlTextReader.Close();
			}
			if (oDTConfigFileInfoForRefCursors != null && oDTConfigFileInfoForRefCursors.storedProcList.ContainsKey(text))
			{
				StoredProcedureInfo storedProcedureInfo = (StoredProcedureInfo)oDTConfigFileInfoForRefCursors.storedProcList[text];
				if (storedProcedureInfo != null && (storedProcedureInfo.m_refCursors.Count > 0 || storedProcedureInfo.m_implicitlyRetRefCursors.Count > 0))
				{
					if (ProviderConfig.m_bTraceLevelPrivate)
					{
						Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.RegAndConfigRdr, OracleTraceFuncName.GetRefCursorInfoForSP, " (REFCURSOR) GetRefCursorInfoForSP(" + text + ") match found!\n");
					}
					if (storedProcedureInfo.m_refCursors.Count > 0)
					{
						return storedProcedureInfo.m_refCursors[0].columnInfo.Copy();
					}
					if (storedProcedureInfo.m_implicitlyRetRefCursors.Count > 0)
					{
						return storedProcedureInfo.m_implicitlyRetRefCursors[0].columnInfo.Copy();
					}
				}
			}
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.RegAndConfigRdr, OracleTraceFuncName.GetRefCursorInfoForSP, " (REFCURSOR) GetRefCursorInfoForSP(" + text + ") no match.\n");
			}
			return null;
		}

		internal override void setudtmapping(out Hashtable s_mapUdtNameToMappingObj)
		{
			s_mapUdtNameToMappingObj = null;
		}
	}
}
